package com.djl.sqtg.controller;

import com.djl.sqtg.entity.Admin;
import com.djl.sqtg.service.IAdminService;
import com.djl.sqtg.util.JsonResult;
import com.djl.sqtg.util.md5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("admin")
public class AdminController extends BaseController{

    @Autowired
    private IAdminService adminService;

    @PostMapping("login")
    public JsonResult<Admin> login(@RequestParam("username") String username, @RequestParam("password") String password) {
        if (md5Util.md5DigestAsHex(password).equals( adminService.getPassword(username))){
            Admin data = adminService.findAdminByUserPwd(username,md5Util.md5DigestAsHex(password));
            return new JsonResult<Admin>(OK,data);
        }
        return new JsonResult<Admin>(NO);
        }
}
